/*
 * @Author: chendeji
 * @Date: 2021-11-16 11:32:12
 * @LastEditTime: 2021-11-16 11:36:35
 * @Description: 
 * @FilePath: \copy_gsy_github_app_flutter\lib\common\net\interceptors\response_interceptor.dart
 * 联系方式：
 * wx: melody_2009
 * qq: 7815171323 
 */
import 'package:dio/dio.dart';

import '../code.dart';
import '../result_data.dart';

class ResponseInterceptors extends InterceptorsWrapper {
  @override
  onResponse(Response response, handler) async {
    RequestOptions option = response.requestOptions;
    var value;
    try {
      var header = response.headers[Headers.contentTypeHeader];
      if ((header != null && header.toString().contains("text"))) {
        value = new ResultData(response.data, true, Code.SUCCESS);
      } else if (response.statusCode! >= 200 && response.statusCode! < 300) {
        value = new ResultData(response.data, true, Code.SUCCESS,
            headers: response.headers);
      }
    } catch (e) {
      print(e.toString() + option.path);
      value = new ResultData(response.data, false, response.statusCode,
          headers: response.headers);
    }
    response.data = value;
    return handler.next(response);
  }
}
